package com.newland.starpos.project.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.newland.starpos.persistent.entity.User;
import com.newland.starpos.persistent.mapper.UserMapper;
import com.newland.starpos.persistent.repository.UserRepository;
import com.newland.starpos.project.utils.BeanUtils;

@Service
public class UserService {

  @Autowired
    private UserRepository userRepository;

	@Autowired
	private UserMapper userMapper;

	public User findOne(String name) {
		PageHelper.startPage(1, 10);
//		List<User> users = userMapper.selectAll();
		int count = userMapper.selectCount(new User());
		System.out.println(count);
//		System.out.println(users.size());
		return userRepository.findByName(name);
	}

	public User save(User user) {
		User mapperUser = new User();
		BeanUtils.copyEntityProperties(user, mapperUser);
		int result = userMapper.insert(user);
		System.out.println(result);
		return userRepository.save(mapperUser);
	}

}
